package com.tuxing.draa_data.util.easyExcel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.tuxing.draa_data.dto.DraaDatabaseDto;
import com.tuxing.draa_data.service.draa.DraaDatabaseService;

/**
 * @author yuanshihang
 * @version 1.0
 * @className DraaDatabaseDataListener
 * @description 基础描述:
 * @date 2021/12/2 20:50
 */
public class DraaDatabaseDataListener implements ReadListener<DraaDatabaseDto> {

    private DraaDatabaseService draaDatabaseService;

    public DraaDatabaseDataListener(DraaDatabaseService draaDatabaseService) {
        this.draaDatabaseService = draaDatabaseService;
    }

    private DraaDatabaseDto draaDatabaseDto;

    @Override
    public void invoke(DraaDatabaseDto draaDatabaseDto, AnalysisContext analysisContext) {
        this.draaDatabaseDto = draaDatabaseDto;
        saveData();
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        saveData();
    }

    private void saveData() {
        draaDatabaseService.saveDraaDatabaseData(draaDatabaseDto);
    }

}
